package day5.problem3;

import java.util.*;

//约瑟夫环问题
//https://www.nowcoder.com/practice/f78a359491e64a50bce2d89cff857eb6?tpId=13&tqId=11199&ru=/exam/oj


public class Solution {
    public int LastRemaining_Solution (int n, int m) {
        if(n == 0 || m == 0) return -1;
        return f(n, m);
    }
    public int f(int n, int m) {
        if(n == 1) return 0;
        int x = f(n-1, m);
        return (m + x) % n;
    }
}